﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BbsbWebService.Classes
{
    public class ValidationState
    {
        private List<string> _errors = new List<string>();

        public IEnumerable<string> Errors
        {
            get
            {
                return _errors;
            }
        }

        public bool IsValid
        {
            get
            {
                return _errors.Count == 0;
            }
        }

        public void AddError(string error)
        {
            _errors.Add(error);
        }

        /// <summary>
        /// This is part of a string format with {0} always being the 'error'
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        public string ToString(string format, params object[] stringFormatArgs)
        {
            StringBuilder builder = new StringBuilder();

            foreach (var error in _errors)
            {
                builder.AppendLine(string.Format(format, error, stringFormatArgs));
            }

            return builder.ToString();
        }

        public override string ToString()
        {
            return this.ToString("** {0}");
        }
    }
}
